package com.int_tech.mession.dao;

import com.int_tech.mession.entity.Mession;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/9/20.
 */
public interface MessionDao extends JpaRepository<Mession,Integer>,JpaSpecificationExecutor<Mession> {

    Mession findMessionByMessionNumber(String messionNumber);


    List<Mession> findByCarNumber(String carNumber);

    List<Mession> findByCarNumberIn(List<String> numbers);

    @Query("select MAX(m.messionCount) from Mession m")
    int findMaxCode();

    Mession findByCarNumberAndIsOver(String carNumber, int isOver);

    Mession findById(int messionId);

    List<Mession> findByIsAnsyCarTime(int status);

    List<Mession> findByIsAnsyCarTimeAndIsOver(int status, int isOver);

    List<Mession> findByIsOver(int i);

    @Query("select m from Mession m where m.carNumber =?1 and m.createTime >=?2 and m.createTime <=?3")
    List<Mession> findByCarNumberAndCreateTime(String carNumber, Date startTime, Date endTime);



    Mession findFirstByIsOverAndYiChangOrderByCreateTimeDesc(int i, int i1);

    Mession findFirstByIsOverAndYiChangOrderByCreateTimeAsc(int i, int i1);

    List<Mession> findByCarNumberInAndCreateTimeAfterAndCreateTimeBefore(List<String> numbers, Date cdate, Date edate);

    List<Mession> findByIsOverAndCreateTimeAfterAndCreateTimeBefore(int i, Date cdate, Date edate);

    Mession findByMessionCount(int maxCode);

    List<Mession> findByEndOpenDoorTime(Date startOpenDoorTime);

    List<Mession> findByStartOpenDoorTime(Date endOpenDoorTime);

//    List<Mession> findByCheckInStatus(int i);

    List<Mession> findByCheckStatus(int i);

    Mession findMessionByMessionNumberAndCarNumber(String messionId, String carNumber);

    List<Mession> findByIsOverAndCheckStatus(int i, int i1);

    List<Mession> findByIsAnsyCarTimeAndIsOverAndYiChangAndCheckStatus(int status, int isOver, int yichang, int checkStatus);

    List<Mession> findByIsAnsyCarTimeAndIsOverAndYiChangAndCheckStatusAndCarNumber(int status, int isOver, int yichang, int checkStatus, String s);

    @Query("select m from Mession m where m.carNumber =?1 and m.createTime >=?2 and m.createTime <=?3 and m.checkStatus =?4 and m.yiChang =?5 and m.isOver =?6")
    List<Mession> findByCarNumberAndCreateTimeAndCheckStatusAndYiChangAndIsOver(String carNumber, Date sTime, Date eTime, int i, int i1, int i2);

    /*Mession findByEndOpenDoorTimeAndIsOverAndYiChangAndCheckStatus(Date startOpenDoorTime, int yichang, int checkStatus);

    Mession findByStartOpenDoorTimeAndIsOverAndYiChangAndCheckStatus(Date endOpenDoorTime, int yichang, int checkStatus);*/

    Mession findByEndOpenDoorTimeAndYiChangAndCheckStatus(Date startOpenDoorTime, int yichang, int checkStatus);

    Mession findByStartOpenDoorTimeAndYiChangAndCheckStatus(Date endOpenDoorTime, int yichang, int checkStatus);

    List<Mession> findByCarNumberInAndCreateTimeAfterAndCreateTimeBeforeAndIsOverAndYiChangAndCheckStatus(List<String> numbers, Date cdate, Date edate, int i, int i1, int i2);

    List<Mession> findByIsOverAndCreateTimeAfterAndCreateTimeBeforeAndYiChangAndCheckStatus(int i, Date cdate, Date edate, int i1, int i2);

    List<Mession> findByCarNumberInAndIsOverAndYiChangAndCheckStatus(List<String> numbers, int i, int i1, int i2);

    Mession findByIdAndCarNumber(int messionId, String carNumber);

    @Query("select count(m) from Mession m where m.messionNumber like CONCAT('%',?1,'%')")
    int countByMessionNumberLike(String time);

    List<Mession> findByIsAnsyCarTimeAndIsOverAndCarNumber(int i, int i1, String s);

    List<Mession> findByStartOpenDoorTimeAndCarNumberAndCreateTimeBefore(Date startOpenDoorTime, String carNumber, Date createTime);

    List<Mession> findByStartCloseDoorTimeAndCarNumberAndCreateTimeBefore(Date startCloseDoorTime, String carNumber, Date createTime);

    List<Mession> findByEndOpenDoorTimeAndCarNumberAndCreateTimeBefore(Date endOpenDoorTime, String carNumber, Date createTime);

    List<Mession> findByEndCloseDoorTimeAndCarNumberAndCreateTimeBefore(Date endCloseDoorTime, String carNumber, Date createTime);

    List<Mession> findByStartOpenDoorTimeAndCarNumberAndCreateTime(Date startOpenDoorTime, String carNumber, Date createTime);

    List<Mession> findByStartCloseDoorTimeAndCarNumberAndCreateTime(Date startCloseDoorTime, String carNumber, Date createTime);

    List<Mession> findByEndOpenDoorTimeAndCarNumberAndCreateTime(Date endOpenDoorTime, String carNumber, Date createTime);

    List<Mession> findByEndCloseDoorTimeAndCarNumberAndCreateTime(Date endCloseDoorTime, String carNumber, Date createTime);

    List<Mession> findByStartOpenDoorTimeAndCarNumberAndIdLessThan(Date startOpenDoorTime, String carNumber, Integer id);

    List<Mession> findByStartCloseDoorTimeAndCarNumberAndIdLessThan(Date startCloseDoorTime, String carNumber, Integer id);

    List<Mession> findByEndOpenDoorTimeAndCarNumberAndIdLessThan(Date endOpenDoorTime, String carNumber, Integer id);

    List<Mession> findByEndCloseDoorTimeAndCarNumberAndIdLessThan(Date endCloseDoorTime, String carNumber, Integer id);


//    List<Mession> findByCheckInAndIsOver(int i, int i1);
}